//
//  ViewController.m
//  Final Ali
//
//  Created by dllo on 16/8/17.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ViewController.h"
#import "FirstTableViewCell.h"
#import "AFNetworking.h"
#import "FirstModel.h"
#import "DataModel.h"
#import "SecDataModel.h"

@interface ViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) FirstModel *first;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self createData];
}

- (void)createData {
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    NSString *str = @"http://api.dongting.com/frontpage/frontpage?location=0&version=1470998222737&app=ttpod&v=v9.0.4.2016070616&user_id=0&mid=iPhone8%2C1&f=f320&s=s310&imsi=&hid=&splus=10.0&active=1&net=2&openudid=4bbd8925c4a3991ee51c9cd8b9a8dc5961820764&idfa=2BBAE4F7-2E3B-41AA-AE0C-F91FB2BDC279&utdid=V62kivWPJBYDABK%2FL8gCUnDI&alf=(null)&bundle_id=com.ttpod.music&latitude=(null)&longtitude=(null)&access_token=(null)&vc=9000400";
    sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
    sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
    sessionManager.requestSerializer.timeoutInterval = 30;
    [sessionManager GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.first = [FirstModel modelWithDic:responseObject];
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.tableView reloadData];
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

    }];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return @"华语音乐";
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableReuse" forIndexPath:indexPath];
    cell.dataArray = self.first.data[indexPath.section + 3].data;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 180;
    } else if (indexPath.section == 1) {
        return 350;
    } else if (indexPath.section == 2) {
        return 370;
    } else {
    return 180;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
